﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF_TEST
{
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            //設置在屏幕中心
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Check();
        }

        private void Check()
        {
            string user = txt_userName.Text;
            string pass = txt_password.Password;
            if (string.IsNullOrWhiteSpace(user))
            {
                MessageBox.Show("請輸入賬號", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (user.Equals("admin") && pass.Equals("admin"))
            {
                //MessageBoxResult result = MessageBox.Show("登錄成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                //if (result == MessageBoxResult.OK)
                //{                 
                //    this.Hide();
                //    MainWindow mainWindow = new MainWindow();
                //    //mainWindow.ShowDialog();
                //    mainWindow.Show();
                //}

                this.Hide(); 
                MainWindow.SingleCase.Show();
            }
            else
            {
                MessageBox.Show("賬號或密碼錯誤", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Check();
            }
        }
    }
}
